package es.ats.codington.web.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.services.VisitorService;

/**
 * Servlet implementation class SingUpForAnEventServlet
 */
@WebServlet("/SingUpForAnEventServlet")
public class SingUpForAnEventServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SingUpForAnEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		HttpSession session = request.getSession(true);
	    Object iD = session.getAttribute("iDVisitor");
	    int id= (Integer) iD;
	    int idevent = Integer.parseInt(request.getParameter("idevent"));
	    
	    try{
	    	VisitorService vs = new VisitorService();
	    	boolean tt = vs.signUpEvent(id, idevent); 

	    	if(	tt==true){
	      	RequestDispatcher rd = request.getRequestDispatcher("ViewMyEventServlet");
	    	 rd.forward(request,response);
	    	}else{
	    		RequestDispatcher rd = request.getRequestDispatcher("ViewMyEventServlet");
		    	 rd.forward(request,response);
	    	}
	    }catch(Exception ex){
	    	
	    	ex.getMessage();
	    }
	    
	    
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
